package com.yugao.fintech.antelope.shop.controller.admin;

import com.yugao.fintech.antelope.base.ram.ActionType;
import com.yugao.fintech.antelope.base.ram.RamResource;
import com.yugao.fintech.antelope.shop.model.rqrs.goods.spec.GoodsSpecResp;
import com.yugao.fintech.antelope.shop.model.rqrs.goods.spec.GoodsSpecSaveReq;
import com.yugao.fintech.antelope.shop.model.rqrs.goods.spec.GoodsSpecUpdateReq;
import com.yugao.fintech.antelope.shop.service.GoodsSpecService;
import com.yugao.fintech.framework.core.response.Resp;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.validation.annotation.Validated;

import java.util.List;

@Api(tags = "商品规格")
@RestController
@RequestMapping("/goodsSpec")
public class GoodsSpecController {
    @Autowired
    private GoodsSpecService goodsSpecService;

    @ApiOperation(value = "分页商品规格")
    @GetMapping("/list")
    @RamResource(action = "goods:spec:query", name = "查询商品规格", type = ActionType.READ)
    public Resp<List<GoodsSpecResp>> pageGoodsSpec() {
        return Resp.ok(goodsSpecService.listGoodsSpec());
    }
  
    @ApiOperation(value = "保存商品规格")
    @PostMapping("/save")
    @RamResource(action = "goods:spec:save", name = "保存商品规格", type = ActionType.WRITE)
    public Resp<?> saveGoodsSpec(@Validated @RequestBody GoodsSpecSaveReq req) {
        return Resp.ok(goodsSpecService.saveGoodsSpec(req));
    }
  
    @ApiOperation(value = "更新商品规格")
    @PostMapping("/update")
    @RamResource(action = "goods:spec:update", name = "更新商品规格", type = ActionType.WRITE)
    public Resp<?> updateGoodsSpec(@Validated @RequestBody GoodsSpecUpdateReq req) {
        return Resp.ok(goodsSpecService.updateGoodsSpec(req));
    }
  
    @ApiOperation(value = "批量删除商品规格")
    @DeleteMapping("/batchDelete")
    @RamResource(action = "goods:spec:delete", name = "删除商品规格", type = ActionType.WRITE)
    public Resp<?> batchDeleteGoodsSpec(@RequestParam(value = "ids") List<Long> ids) {
        return Resp.ok(goodsSpecService.batchDeleteGoodsSpec(ids));
    }
  
    @ApiOperation(value = "删除商品规格")
    @DeleteMapping("/delete")
    @RamResource(action = "goods:spec:delete", name = "删除商品规格", type = ActionType.WRITE)
    public Resp<?> deleteGoodsSpec(@RequestParam(value = "id") Long id) {
        return Resp.ok(goodsSpecService.deleteGoodsSpec(id));
    }
}
